from numpy import *
import matplotlib.pyplot as plt
from scipy.misc import derivative

def set_ax(plt):
    ax = plt.gca()
    ax.xaxis.set_ticks_position('bottom')
    ax.yaxis.set_ticks_position('left')
    ax.spines['bottom'].set_position(('data', 0))
    ax.spines['left'].set_position(('data', 0))
    ax.spines['right'].set_color('none')
    ax.spines['top'].set_color('none')

def f(x):
    return sin(x)

if __name__=='__main__':
    x = arange(-3,3,0.01)
    
    df = derivative(f, x, dx=1e-6)
    
    plt.plot(x, f(x), color='b')
    plt.plot(x, df, color='r')
    set_ax(plt)
    plt.show()
    